package com.wm.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wm.bean.Order;
import com.wm.bean.OrderMenu;
import com.wm.dao.OrderMenuDAO;

/**
 * @author yangbo
 *
 * 2012-12-26
 */
public class OrderMenuHibernateDAO extends HibernateDaoSupport implements OrderMenuDAO {
	
	private static final String LOAD_BY_ID = "from OrderMenu where id = ?";
	private static final String LOAD_BY_ORDERID = "from OrderMenu where orderId = ?";
	
	/**
	 * 添加
	 * @param o
	 * @return
	 */
	public OrderMenu saveOrderMenu(OrderMenu o){
		this.getHibernateTemplate().save(o);
		return o;
	}
	
	/**
	 * 修改
	 * @param o
	 * @return
	 */
	public OrderMenu updateOrderMenu(OrderMenu o){
		this.getHibernateTemplate().update(o);
		return o;
	}
	
	/**
	 * 删除
	 * @param o
	 */
	public void removeOrderMenu(OrderMenu o){
		this.getHibernateTemplate().delete(o);
	}
	
	/**
	 * 根据ID查询
	 * @param id
	 * @return
	 */
	public OrderMenu findOrderMenuById(long id){
		Object[] obj={new Long(id)};
		List l = this.getHibernateTemplate().find(LOAD_BY_ID,obj);
		if(l == null || l.isEmpty()){
			return null;
		}else{
			return (OrderMenu) l.get(0);
		}
	}
	
	/**
	 * 根据订单ID查询
	 * @param orderId
	 * @return
	 */
	public OrderMenu findOrderMenuByOrderId(long orderId){
		Object[] obj={new Long(orderId)};
		List l = this.getHibernateTemplate().find(LOAD_BY_ORDERID,obj);
		if(l == null || l.isEmpty()){
			return null;
		}else{
			return (OrderMenu) l.get(0);
		}
	}
}
